<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>取值赋值</title>
    <link rel="stylesheet" href="../lib/layui-v2.5.7/layui/css/layui.css">
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
    </style>
</head>
<body>

    <div class="layui-container">
        <div class="layui-form" lay-filter="formEle">
            <input type="text" class="layui-input" name="username">
            <input type="password" class="layui-input" name="password">
            <button class="layui-btn">提交</button>
        </div>
    </div>

    <script src="../lib/layui-v2.5.7/layui/layui.all.js"></script>
    <script type="text/javascript">
        var form = layui.form,
            $ = layui.$;

        $(".layui-btn").click(function (){
            // form.val("lay-filter"); 获取lay-filter对应表单中 name=value 组成的对象
            // console.log(form.val("formEle"));
            // form.val("lay-filter", { xxx }); 给lay-filter对应表单赋值
            form.val("formEle", {
                username: "张飞",
                password: "3456789" 
            })
        })
    </script>
</body>
</html>